package com.handong.handserialprogram.model.entities;

import android.os.Parcel;
import android.os.Parcelable;

import com.handong.handserialprogram.model.status.FootRingStatus;

import java.io.Serializable;

/**
 * Created by Administrator on 2016/12/21.
 */
public class FootRingEntity implements Parcelable,Serializable {
    /**
     * 实体数据
     */
    private float actualRingDistance = 0.0F;//实测距离
    private int lockType = 1;//锁的状态
    private String ringID;//脚环ID
    private int ringPower;//电量
    private int setRingDistance = 3;//设置的距离
    private byte simStatus;
    private String IMEI_CCR="";
    private String ip;
    private String port;
    private String sim;
    private String version;
    private int voiceNumber;

    /**
     * 定义数据-------------
     */
    private boolean brokenType = false;//防拆 true已被破坏
    private boolean isAction = false;
    private boolean isNormalWork = false;//正常工作
    private boolean myBingding=false;//是否是自己绑定的
    private boolean isBingding=false;//是否被绑定

    public boolean isEmpower() {
        return isEmpower;
    }

    public void setEmpower(boolean empower) {
        isEmpower = empower;
    }

    private boolean isEmpower=false;//是否授权打开
    private boolean isRefresh = false;
    public static final int LOCK_OPEN = 1;//锁开
    public static final int LOCK_CLOSE = 0;//锁关
    public static final int LOCK_EMPOWER_OPEN=2;//授权打开
    public static final short LONG_WAIT = 60;
    public static final int STATE_NORMAL_LIMIT = 20;//42
    public static final int STATE_ESCAPE_LIMIT = 30;//57
    private short actionCount = 0;//活动数
    private int noDataTime = 0;//时间
    private byte actionOrder = 0;


    public FootRingEntity() {
    }

    protected FootRingEntity(Parcel in) {
        ringID = in.readString();
        setRingDistance = in.readInt();
        actualRingDistance = in.readFloat();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(ringID);
        dest.writeInt(setRingDistance);
        dest.writeFloat(actualRingDistance);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<FootRingEntity> CREATOR = new Creator<FootRingEntity>() {
        @Override
        public FootRingEntity createFromParcel(Parcel in) {
            return new FootRingEntity(in);
        }

        @Override
        public FootRingEntity[] newArray(int size) {
            return new FootRingEntity[size];
        }
    };

    public void addActionCount() {
        if (this.actionCount <= LONG_WAIT) {
            this.actionCount++;
        }
    }

    public void calculateTime() {
        if (this.noDataTime <= STATE_ESCAPE_LIMIT) {
            this.noDataTime += 1;
            return;
        }
        this.actualRingDistance = 0.0f;
    }
    /**
     * 判断脚环状态-超时处理
     * @return
     */
    public int getStatus() {
        if (this.noDataTime <= STATE_NORMAL_LIMIT) {//7秒
            return FootRingStatus.NORMAL;
        }
        if (this.noDataTime > STATE_NORMAL_LIMIT && this.noDataTime < STATE_ESCAPE_LIMIT){//7-10秒
            return FootRingStatus.EXCEPTION;
        }
        return FootRingStatus.ESCAPE;//大于等于30就是逃脱
    }

    public short getActionCount() {
        return this.actionCount;
    }

    public byte getActionOrder() {
        return this.actionOrder;
    }

    public float getActualRingDistance() {
        return this.actualRingDistance;
    }

    public boolean getBrokenType() {
        return this.brokenType;
    }

    public int getLockType() {
        return this.lockType;
    }

    public int getNoDataTime() {
        return this.noDataTime;
    }

    public String getRingID() {
        return this.ringID;
    }

    public int getRingPower() {
        return this.ringPower;
    }

    public int getSetRingDistance() {
        return this.setRingDistance;
    }



    public boolean isAction() {
        return this.isAction;
    }

    public boolean isNormalWork() {
        return this.isNormalWork;
    }

    public boolean isRefresh() {
        return this.isRefresh;
    }

    public void resetActionCount() {
        this.actionCount = 0;
    }

    public void resetActionOrder() {
        this.actionOrder = 0;
    }

    public void resetTime() {
        this.noDataTime = 0;
    }

    public void setAction(boolean paramBoolean) {
        this.isAction = paramBoolean;
    }

    public void setActionOrder(byte paramByte) {
        this.actionOrder = paramByte;
    }

    public void setActualRingDistance(float paramFloat) {
        this.actualRingDistance = paramFloat;
    }

    public void setBrokenType(boolean paramString) {
        this.brokenType = paramString;
    }

    public void setLockType(int paramInt) {
        this.lockType = paramInt;
    }

    public void setNormalWork(boolean paramBoolean) {
        this.isNormalWork = paramBoolean;
    }

    public void setRefresh(boolean paramBoolean) {
        this.isRefresh = paramBoolean;
    }

    public void setRingID(String paramString) {
        this.ringID = paramString;
    }

    public void setRingPower(int paramString) {
        this.ringPower = paramString;
    }

    public void setSetRingDistance(int paramInt) {
        this.setRingDistance = paramInt;
    }

    public byte getSimStatus() {
        return simStatus;
    }

    public void setSimStatus(byte simStatus) {
        this.simStatus = simStatus;
    }

    public String getIMEI_CCR() {
        return IMEI_CCR;
    }

    public void setIMEI_CCR(String IMEI_CCR) {
        this.IMEI_CCR = IMEI_CCR;
    }

    public boolean isMyBingding() {
        return myBingding;
    }

    public void setMyBingding(boolean myBingding) {
        this.myBingding = myBingding;
    }

    public boolean isBingding() {
        return isBingding;
    }

    public void setBingding(boolean bingding) {
        isBingding = bingding;
    }


    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

    public String getSim() {
        return sim;
    }

    public void setSim(String sim) {
        this.sim = sim;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public int getVoiceNumber() {
        return voiceNumber;
    }

    public void setVoiceNumber(int voiceNumber) {
        this.voiceNumber = voiceNumber;
    }

    @Override
    public boolean equals(Object object) {
        if(object==null)return false;
        if(object instanceof FootRingEntity ){
            FootRingEntity entity = (FootRingEntity) object;
            return this.ringID.equals(entity.getRingID());
        }
     return false;
    }

    public String toString() {
        return "FootRing:" + this.ringID + ", normalWork:" + this.isNormalWork + ", actionCount:" + this.actionCount;
    }

    public void setNoDataTime(int noDataTime) {
        this.noDataTime = noDataTime;
    }
}
